package com.kj.xuyuan.chat;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.kj.xuyuan.R;
import com.kj.xuyuan.adapter.FriendAdapter;
import com.kj.xuyuan.base.BaseActivity;
import com.kj.xuyuan.base.BaseModel;
import com.kj.xuyuan.base.Constants;
import com.kj.xuyuan.http.JsonCallback;
import com.kj.xuyuan.http.OkGoUtil;
import com.kj.xuyuan.http.UrlConstants;
import com.kj.xuyuan.model.FriendBean;
import com.kj.xuyuan.model.UserInfoBean;
import com.kj.xuyuan.util.LogUtils;
import com.kj.xuyuan.util.SPUtils;
import com.kj.xuyuan.util.ToastUtil;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 我的好友
 * 好友申请
 * 我的申请
 */
public class FriendListActivity extends BaseActivity {

    @BindView(R.id.rv_friend)
    RecyclerView rvFriend;

    private int type;//1我的好友  2好友申请  3我的申请
    private List<FriendBean> data;
    private FriendAdapter adapter;

    public static void actionStar(Context context,int type){
        Intent intent = new Intent(context,FriendListActivity.class);
        intent.putExtra("type",type);
        context.startActivity(intent);
    }

    @Override
    protected void init(Bundle savedInstanceState) {

    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.activity_friend_list;
    }

    @Override
    protected void initView() {
        type = getIntent().getIntExtra("type",-1);
        if(type == -1){
            ToastUtil.showDataErrorToast(context);
            finish();
            return;
        }
        setTitleText(type == 1 ? "我的好友" : type == 2 ? "好友申请" : "我的申请");
        initRecyclerView();
        getData();
    }

    private void getData() {
        String url = type == 1 ? UrlConstants.FRIEND_LIST : UrlConstants.REQUEST_FRIEND_LIST;
        Map map = new HashMap();
        map.put("id", SPUtils.getIntData(getContext(), Constants.UID,0)+"");


        OkGoUtil.postRequest(getContext(), url, map, new JsonCallback<BaseModel<List<FriendBean>>>() {
            @Override
            public void onSuccess(Response<BaseModel<List<FriendBean>>> response) {
                if (response != null && response.body() != null) {
                    if(response.body().getCode() == 1){

                    }
                    ToastUtil.showToast(getContext(),response.body().getMsg());
                }
            }

            @Override
            public void onError(Response<BaseModel<List<FriendBean>>> response) {
                super.onError(response);
                LogUtils.e(TAG,response.getException().getMessage());
            }
        });
    }

    private void initRecyclerView() {
        data = new ArrayList<>();
        adapter = new FriendAdapter();
        rvFriend.setLayoutManager(new LinearLayoutManager(context));
        rvFriend.setAdapter(adapter);
        adapter.setNewData(data);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getTitleBarType() {
        return 0;
    }
}